#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
//线程函数
//int pthread_create(pthread_t *thread, const pthread_attr_t *attr,void *(*start_routine) (void *), void *arg);
void *threadFun(void *arg)
{
    
    int i = 10;
    //强转
    int *p = (int *)arg;
    while(i--)
    {
        (*p)++;
        sleep(1);
        printf("hello,%d\n",*p);
        if(i == 5)
        {
            char buf[128] = {"hahahaha"};
            pthread_exit(buf);
        }
    }
}

int main()
{
    int val = 0;
    pthread_t tid;
    pthread_create(&tid,NULL,threadFun,(void *)&val);
    printf("in main thread ID = %ld\n",tid);
    int i = 20;
    while(i--)
    {
        printf("i = %d\n",i);
        sleep(1);
        if(i == 12)
        {
            pthread_cancel(tid);
        }
    }
    return 0;
}